package com.yidu.hbatsams.service.Impl;

import com.yidu.hbatsams.dao.UserRoleMapper;
import com.yidu.hbatsams.domain.UserRole;
import com.yidu.hbatsams.domain.vo.UserRoleVo;
import com.yidu.hbatsams.domain.vo.UserVo;
import com.yidu.hbatsams.service.UserRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/*
 * @Author 梁海长
 * @Description //TODO
 * @Date 18:19 2019/10/28 0028
 * @Param 
 * @return 
 **/
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Resource
    UserRoleMapper userRoleMapper;


    @Override
    public List<UserRoleVo> findUserId(HttpSession session) {
        UserVo userVo = (UserVo)session.getAttribute("user");
        List<UserRole> list = userRoleMapper.findUserId(userVo.getUserId());
        List<UserRoleVo> listVo = new ArrayList<UserRoleVo>();
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            UserRole userRole = (UserRole) iterator.next();
                UserRoleVo userRoleVo = new UserRoleVo();
                BeanUtils.copyProperties(userRole, userRoleVo);
                userRoleVo.setRole(userRole.getRoleId());
                listVo.add(userRoleVo);
        }

        return listVo;
    }


}
